<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<?php
/**
 * Created by PhpStorm.
 * User: dapeng
 * Date: 2018/9/26
 * Time: 下午4:32
 */

//确认好环境后支持后,就可以只是用PDO对象
//phpinfo();
//1、准备连接数据库
$pdo = new PDO("mysql:dbname=test0925;host=127.0.0.1","root","123456");


//如何从数据库中查询出数据显示到页面的表格中
$sql = "SELECT * FROM dc_user;";

//用于执行SQL并查询的数据库的结果
$res = $pdo->query($sql);

echo "<table border='1' >";

echo "<tr>
<th>编号</th>
<th>名字</th>
<th>学号</th>
<th>电话</th>
<th>性别</th>
<th>年龄</th>
<th>地址</th>


</tr>";
//遍历数据库里面得到的结果
foreach ($res as $user){

    echo "<tr>";
    //把数据显示到表格中
//    var_dump($user['name']);
        echo "<td>{$user['id']}</td>";
        echo "<td>{$user['name']}</td>";
        echo "<td>{$user['no']}</td>";
        echo "<td>{$user['tel']}</td>";
        echo "<td>{$user['sex']}</td>";
        echo "<td>{$user['age']}</td>";
        echo "<td>{$user['address']}</td>";

    echo "</tr>";
}

echo "</table>";

echo "<table border='1' >
    <tr>
        <td>1</td>
        <td>2</td>
        <td>3</td>
    </tr>
    <tr>
        <td>1</td>
        <td>2</td>
        <td>3</td>
    </tr>
</table>";




//用于增删改
//$pdo->exec();




//var_dump($pdo);

